package com.min.spring.controller;

import com.min.spring.entity.Server;
import com.min.spring.service.MysqlInfoService;
import com.min.spring.util.MysqlInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * 服务器监控
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/monitor/server")
public class ServerController
{
    @Autowired
    MysqlInfoService mysqlInfoService;

    @GetMapping()
    public String server(ModelMap mmap) throws Exception
    {
        Server server = new Server();
        server.copyTo();
        mmap.put("server", server);



        mmap.put("variableMap", mysqlInfoService.getVariables());
        mmap.put("statusMap", mysqlInfoService.getStatus());


//        // 创建对象
//        MysqlInfo mysqlInfo = new MysqlInfo();
//        //show variables
//        Map<String, String> variableMap = mysqlInfo.getVariables();
//        if (variableMap != null) {
//            System.out.println("自动commit : " + variableMap.get("autocommit"));
//            System.out.println("程序主目录 : " + variableMap.get("basedir"));
//        }
//        mmap.put("variableMap", variableMap);
//        //SHOW status
//        Map<String, String> statusMap = mysqlInfo.getStatus();
//        if (statusMap != null) {
//            System.out.println("创建的线程 : " + statusMap.get("Threads_created"));
//            System.out.println("运行的线程 : " + statusMap.get("Threads_running"));
//        }
//        mmap.put("statusMap", statusMap);
//        mysqlInfo.colseCon();

        return "server";
    }
}
